home *** CD-ROM | disk | FTP | other *** search
- ;unsigned short seek_char(strg,ch,start_pt);
- ; unsigned char *strg,ch,start_pt;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _seek_char
- _seek_char proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- mov _error_code,1 ;1 = error occurred
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,dword ptr[bp+4] ; ES:DI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L1 ;
- L0: mov di,[bp+4] ;NEAR case
- mov ax,ds ;ES = DS
- mov es,ax ;
- L1: mov dh,[bp+6] ;DH holds the char sought
- sub cx,cx ;counter
- mov cl,[bp+8] ;start point
- inc cl ;count from 1
- mov ax,cx ;AX holds string position
- dec ax ;adjust
- cmp cl,1 ;need to forward ptr?
- je L3 ;jump if not
- L2: cmp byte ptr es:[di],0 ;end of string?
- je L4 ;quit if so
- inc di ;forward ptr for next time
- loop L2 ;loop
- dec di ;
- L3: mov dl,es:[di] ;now start seeking the char
- inc ax ;forward strg ptr
- cmp dl,dh ;the search char?
- je L5 ;jump if found
- cmp dl,0 ;end of string?
- je L4 ;jump if so
- inc di ;
- jmp short L3 ;go get next char
- L4: sub ax,ax ;char not found, return zero
- jmp short L6 ;jump ahead
- L5: dec _error_code ;0 = no error
- L6: pop si ;
- pop di ;
- pop bp ;
- dec ax ;count return value from 0
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _seek_char ENDP
- _TEXT ENDS
- END